package com.qfedu.stussm.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qfedu.stussm.dao.TprizeDao;
import com.qfedu.stussm.dto.TccardDto;
import com.qfedu.stussm.dto.TprizeDto;
import com.qfedu.stussm.entity.Tprize;
import com.qfedu.stussm.service.intf.TprizeService;
import com.qfedu.stussm.vo.PageBeanVo;
import com.qfedu.stussm.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TprizeServiceImpl implements TprizeService {
    @Autowired
    private TprizeDao dao;
    @Override
    public R add(Tprize tprize) {
        if(dao.add(tprize) > 0){
            return R.ok();
        }else{
            return R.fail();
        }
    }

    @Override
    public PageBeanVo selectLikeAll(String t_name, int page, int limit) {
        PageHelper.startPage(page,limit);
        if(t_name != null && t_name.length() > 0){
            t_name = "%"+t_name+"%";
        }else{
            t_name = null;
        }
        PageInfo<TprizeDto> pageInfo = new PageInfo<>(dao.selectLikeAll(t_name));
        return new PageBeanVo(pageInfo.getTotal(),pageInfo.getList());
    }

    @Override
    public R delete(int t_tpid) {
        if(dao.delete(t_tpid) > 0){
            return R.ok();
        }else{
            return R.fail();
        }
    }

    @Override
    public R update(Tprize tprize) {
       if(dao.update(tprize) > 0){
           return R.ok();
       }else{
           return R.fail();
       }
    }
}
